﻿using FTBS.Models.Entities;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace FTBS.Models.DAO
{
    public class RoomDAO
    {
        private FilmTicketBookingSystemEntities _entities = new FilmTicketBookingSystemEntities();

        /// <summary>
        /// Get all room
        /// </summary>
        /// <returns>List of room</returns>
        /// <author>vuongvt</author>
        public IEnumerable<Room> GetListRoom()
        {
            try
            {
                IEnumerable<Room> listRoom = new List<Room>();
                listRoom = _entities.Rooms.ToList().Where(room => room.IsDeleted == false);
                return listRoom;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        /// <summary>
        /// Get list room by theaterId. It is used when choose a theater -> load all room of this theater
        /// </summary>
        /// <param name="theaterId">TheaterId</param>
        /// <returns>SelectList of Room</returns>
        /// <author>vuongvt</author>
        public SelectList GetSelectedListRoomByTheater(int theaterId)
        {
            try
            {
                IEnumerable<SelectListItem> listRoom = new List<SelectListItem>();
                listRoom = (from room in _entities.Rooms
                            where room.TheaterId == theaterId
                                  && room.IsDeleted == false
                            select room).AsEnumerable().Select(room => new SelectListItem() { Value = room.RoomId.ToString(), Text = room.RoomName });
                return new SelectList(listRoom, "Value", "Text");
            }
            catch (Exception ex)
            {
                throw ex;
            }
            
        }

        /// <summary>
        /// Get list room by theaterId
        /// </summary>
        /// <param name="theaterId"></param>
        /// <returns>List of room</returns>
        /// <author>vuongvt</author>
        public List<Room> GetListRoomByTheater(int theaterId)
        {
            try
            {
                List<Room> listRoom = new List<Room>();
                listRoom = _entities.Rooms.Where(room => room.TheaterId == theaterId && room.IsDeleted == false).ToList();
                return listRoom;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
    }
}